/**
 * description：权限处理
 * author：wangqingqing
 * */
import router from './router';
import store from './store';

/* todo 白名单页面 */
let whiteList = ['/login', '/register'];
/* todo router.beforeEach */
router.beforeEach(async (to, from, next) => {
    let adminToken = '';
    if (window.localStorage && window.localStorage.adminToken) {
        adminToken = window.localStorage.adminToken;
    }
    if (store.state.adminToken) {
        adminToken = store.state.adminToken;
    }
    if (adminToken) {
        if (to.path === '/login') {
            /* 有登陆信息直接跳转到首页 */
            next('/personal');
        } else {
            next();
        }
    } else {
        if (whiteList.includes(to.path)) {
            next();
        } else {
            /* 没有登陆跳转到登陆页面 */
            next('/login');
        }
    }
});
